package cate.game.pvp.pointrace.data;

import cate.game.util.GameKit;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.data.annotation.Id;

import static cate.game.pvp.pointrace.data.PointRaceRankRwd.RwdType.DAY;
import static cate.game.pvp.pointrace.data.PointRaceRankRwd.RwdType.SEASON;

@Data
public class PointRaceRankRwd {

    public static PointRaceRankRwd ofDay(String uid, int season, int srvId, int rank, String reward, int day) {
        return of(uid, season, srvId, rank, reward, day, DAY);
    }

    public static PointRaceRankRwd ofSeason(String uid, int season, int srvId, int rank, String reward, int day) {
        return of(uid, season, srvId, rank, reward, day, SEASON);
    }

    public static PointRaceRankRwd of(String uid, int season, int srvId, int rank, String reward, int day, RwdType rwdType) {
        PointRaceRankRwd rwd = new PointRaceRankRwd();
        rwd.setUid(uid);
        rwd.setSeason(season);
        rwd.setSrvId(srvId);
        rwd.setRank(rank);
        rwd.setReward(reward);
        rwd.setDay(day);
        rwd.setRwdType(rwdType);
        return rwd;
    }

    @Id
    private String id = GameKit.uid();

    private String uid;
    private int season;
    private int srvId;
    private int rank;
    private String reward;
    private int day;
    private RwdType rwdType = DAY;


    public enum RwdType {
        DAY, SEASON;
    }

    @JsonIgnore
    public String getSrvIdIndexName() {
        return String.format("%d-%d-%d-%d", season, srvId, day, rwdType.ordinal());
    }

    @JsonIgnore
    public String getIndexedKey() {
        return String.format("%s-%d-%d-%d-%d", uid, season, srvId, day, rwdType.ordinal());
    }
}
